﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class Manage_exams : ManagePageBase {
    protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack)
        {
            bind();
        }
    }

    private void bind()
    {
        string SQL = "SELECT StudentExam.PaperId,Paper.PaperName FROM StudentExam LEFT JOIN Paper ON StudentExam.PaperId=Paper.PaperId GROUP BY StudentExam.PaperId, Paper.PaperName";

        DataTable dt = Exam.Core.DAL.DataProvider.getDataTable(SQL);
        rp.DataSource = dt;
        rp.DataBind();
    }

    protected void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView rw = (DataRowView)e.Item.DataItem;
            string _id = rw["PaperId"].ToString();

            if (_id == "")
                return;
            List<Exam.Core.Model.PaperQuestionType> model = new Exam.Core.DAL.Paper().getPaperById(int.Parse(_id)).PaperQuestionTypes;
            StringBuilder sb = new StringBuilder();
            float total = 0;
            int totalCount = 0;
            foreach (Exam.Core.Model.PaperQuestionType o in model)
            {
                sb.Append(o.QuestionTypeTitle.Trim() + o.QuestionCount.Trim() + "，");
                total = total + float.Parse(o.Score.Trim()) * int.Parse(o.QuestionCount.Trim());
                totalCount = totalCount + int.Parse(o.QuestionCount.Trim());
            }
            string tmp = Resources.labels.paper_qtotal_score;
            tmp = String.Format(tmp, totalCount, total);
            //sb.Append("共计" + totalCount + "道试题，");
            //sb.Append("总分" + total + "分。");
            sb.Append(tmp);
            //获取考试人数
            string SQL = "SELECT COUNT(*) FROM StudentPaper WHERE PaperID=" + _id;
            object y = Exam.Core.DAL.DataProvider.GetSingle(SQL);
            string yc = "0";
            if (null != y) { yc = y.ToString(); }
            tmp = Resources.labels.paper_stutotal;
            tmp = String.Format(tmp, yc);
            sb.Append(tmp);



            Literal litTj = (Literal)e.Item.FindControl("litTj");
            litTj.Text = sb.ToString();
        }

    }


}
